package cn.kgc.mes.workorder.service.impl;

import java.util.List;
import cn.kgc.mes.common.utils.DateUtils;
import cn.kgc.mes.routeprocess.domain.RouteProcess;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.kgc.mes.workorder.mapper.ProWorkorderMapper;
import cn.kgc.mes.workorder.domain.ProWorkorder;
import cn.kgc.mes.workorder.service.IProWorkorderService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 生产工单Service业务层处理
 * 
 * @author cly
 * @date 2025-09-11
 */
@Service
public class ProWorkorderServiceImpl extends ServiceImpl<ProWorkorderMapper, ProWorkorder> implements IProWorkorderService
{
    @Autowired
    private ProWorkorderMapper proWorkorderMapper;

    /**
     * 查询生产工单
     * 
     * @param workorderId 生产工单主键
     * @return 生产工单
     */
    @Override
    public ProWorkorder selectProWorkorderByWorkorderId(Long workorderId)
    {
        return proWorkorderMapper.selectProWorkorderByWorkorderId(workorderId);
    }

    /**
     * 查询生产工单列表
     * 
     * @param proWorkorder 生产工单
     * @return 生产工单
     */
    @Override
    public List<ProWorkorder> selectProWorkorderList(ProWorkorder proWorkorder)
    {
        return proWorkorderMapper.selectProWorkorderList(proWorkorder);
    }
    @Override
    public List<ProWorkorder> selectProWorkorderList2(ProWorkorder proWorkorder)
    {
        return proWorkorderMapper.selectProWorkorderList2(proWorkorder);
    }

    /**
     * 新增生产工单
     * 
     * @param proWorkorder 生产工单
     * @return 结果
     */
    @Transactional
    @Override
    public int insertProWorkorder(ProWorkorder proWorkorder)
    {
        proWorkorder.setCreateTime(DateUtils.getNowDate());
        int i = proWorkorderMapper.insertProWorkorder(proWorkorder);
        if (i > 0){
            return proWorkorder.getWorkorderId().intValue();
        }
        return 0;
    }

    /**
     * 修改生产工单
     * 
     * @param proWorkorder 生产工单
     * @return 结果
     */
    @Override
    public int updateProWorkorder(ProWorkorder proWorkorder)
    {
        proWorkorder.setUpdateTime(DateUtils.getNowDate());
        return proWorkorderMapper.updateProWorkorder(proWorkorder);
    }

    /**
     * 批量删除生产工单
     * 
     * @param workorderIds 需要删除的生产工单主键
     * @return 结果
     */
    @Override
    public int deleteProWorkorderByWorkorderIds(Long[] workorderIds)
    {
        return proWorkorderMapper.deleteProWorkorderByWorkorderIds(workorderIds);
    }

    /**
     * 删除生产工单信息
     * 
     * @param workorderId 生产工单主键
     * @return 结果
     */
    @Override
    public int deleteProWorkorderByWorkorderId(Long workorderId)
    {
        return proWorkorderMapper.deleteProWorkorderByWorkorderId(workorderId);
    }
    //根据当前产品编码取出工艺过程集合
    public List<RouteProcess> getWorkList(String productCode){
        return proWorkorderMapper.getWorkList(productCode);
    }

    @Override
    public List<ProWorkorder> selectWorkorderWeekAndNum() {
        return proWorkorderMapper.selectWorkorderWeekAndNum();
    }
}
